<template>
  <section class="container">
    {{msg}}
    {{$route.query.id}}
    <div>{{getUser}}</div>
    <button @click="createUsr">生成user</button>
    {{agetn}}
    <router-link :to='{name:"user-friend"}'>friend</router-link>
    <bdMap />
  </section>
</template>

<script>
import bdMap from '~/components/bdMap'

export default {
  name:"friend",
  asyncData(){
    /*它可以在服务端或路由更新之前被调用。在这个方法被调用的时候，第一个参数被设定为当前页面的上下文对象，你可以利用 asyncData方法来获取数据并返回给当前组件。*/
      console.log("组件创建前异步执行区域");
  },
    data(){
      return {
        msg:"这里是friend页面",
        user:this.$store.getters.loggedUser,
        agetn:this.$store.getters.agent,
        showMap:false
      }
    },
    head(){
        return {
          title:"friend页面",
           meta: [
                { hid: 'description', name: 'description', content: '这个是页面描述部分' },
                { hid: 'keyword', name: 'keyword', content: '这个,是,页面,描述,部分' }
              ],
        }
    },
     components:{
        bdMap
    },
    methods:{
      createUsr(){
        this.$store.dispatch("setUser",this.msg);

        //this.user = this.$store.getters.loggedUser;
      }
    },
    computed:{
      getUser(){
        return this.$store.getters.loggedUser
      }
    },
    created(){
     
      console.log("创建组件");
      //console.log(this.$store.getters.loggedUser);
    },
    mounted(){
      var self = this;
      setTimeout(function(){
        createScript(['http://api.map.baidu.com/api?v=2.0&ak=3GEIYwhwIw0aKcaFOKpsDiOAWsoDAVam'],"#scriptLink",function(){
          self.showMap = true;
        });
      },1000)
     
      //console.log("body"+$('body').html());
      console.log("组件创建完成");
    }
  
}
</script>